<%@ page import="dao.BlogDao" %>
<%@ page import="dao.impl.BlogDaoImpl" %>
<%@ page import="entity.Blog" %>
<%@ page import="dao.CommentDao" %>
<%@ page import="dao.impl.CommentDaoImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Comment" %>
<%@ page import="entity.User" %>
<%@ page import="service.BlogService" %>
<%@ page import="service.impl.BlogServiceImpl" %>
<%@ page import="service.CommentService" %>
<%@ page import="service.impl.CommentServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%

    //设置解码方式
    request.setCharacterEncoding("utf-8");
    //获取值
    String opr=request.getParameter("opr");
    //获取微博id
    int bid=Integer.parseInt(request.getParameter("id"));

    BlogService blogService=new BlogServiceImpl();
    CommentService commentService=new CommentServiceImpl();



    if (opr.equals("commentList")){
        //接收值
        Blog blog=blogService.getBlogById(bid);
        List<Comment> commentList =commentService.getCommentList(bid);
        //存值
        session.setAttribute("blog",blog);
        session.setAttribute("commentList",commentList);
        request.getRequestDispatcher("../pages/detail.jsp").forward(request,response);
    }else if (opr.equals("addComment")){
        //获取多行文本域的值
        String content=request.getParameter("t_content");
        if (content==null || content.equals("")){
%>

<script>
    alert("你的回复没有输入任何内容！！")
    window.history.back(-1);
</script>

<%
    }else {
     Comment comment=new Comment();
     //赋值
     comment.setUid(((User)session.getAttribute("user")).getId());
     comment.setBid(bid);
     comment.setContent(content);

     int i=commentService.addComment(comment);

     if (i>0){
         //刷新当前页面
         response.sendRedirect(request.getHeader("Referer"));
     }
    }
}


%>